#pragma once

#include "ObjectFlow.h"

#include "Behavior.h"

namespace uml {

const bool ObjectFlow::isMulticast_default_ = false;
const bool ObjectFlow::isMultireceive_default_ = false;
ObjectFlow::ObjectFlow(const QString& umlType)
    : ActivityEdge(umlType) {}

void ObjectFlow::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    ActivityEdge::fromJson(json, errorList);
    isMulticast_ = json.value("isMulticast").toBool(isMulticast_default_);
    isMultireceive_ = json.value("isMultireceive").toBool(isMultireceive_default_);
    selection_ = JsonSerializable::create<Behavior>(json.value("selection"), errorList);

    transformation_ = JsonSerializable::create<Behavior>(json.value("transformation"), errorList);

}

void ObjectFlow::toJson(QJsonObject& json) {
    ActivityEdge::toJson(json);
    if (isMulticast_ != isMulticast_default_) {
        json.insert("isMulticast", isMulticast_);
    }
    if (isMultireceive_ != isMultireceive_default_) {
        json.insert("isMultireceive", isMultireceive_);
    }
    if (selection_) {
        QJsonObject selection_json;
        selection_->toJson(selection_json);
        json.insert("selection", selection_json);
    }
    if (transformation_) {
        QJsonObject transformation_json;
        transformation_->toJson(transformation_json);
        json.insert("transformation", transformation_json);
    }
}

/// <summary>
/// isMulticast getter
/// Indicates whether the objects in the ObjectFlow are passed by multicasting.
/// </summary>
bool ObjectFlow::isMulticast() const {
    return isMulticast_;
}

/// <summary>
/// isMulticast setter
/// Indicates whether the objects in the ObjectFlow are passed by multicasting.
/// </summary>
void ObjectFlow::setIsMulticast(bool value) {
    isMulticast_ = value;
}

/// <summary>
/// isMultireceive getter
/// Indicates whether the objects in the ObjectFlow are gathered from respondents to
/// multicasting.
/// </summary>
bool ObjectFlow::isMultireceive() const {
    return isMultireceive_;
}

/// <summary>
/// isMultireceive setter
/// Indicates whether the objects in the ObjectFlow are gathered from respondents to
/// multicasting.
/// </summary>
void ObjectFlow::setIsMultireceive(bool value) {
    isMultireceive_ = value;
}

/// <summary>
/// selection getter
/// A Behavior used to select tokens from a source ObjectNode.
/// </summary>
shared_ptr<Behavior> ObjectFlow::selection() const {
    return selection_;
}

/// <summary>
/// selection setter
/// A Behavior used to select tokens from a source ObjectNode.
/// </summary>
void ObjectFlow::setSelection(shared_ptr<Behavior> value) {
    selection_ = value;
}

/// <summary>
/// transformation getter
/// A Behavior used to change or replace object tokens flowing along the ObjectFlow.
/// </summary>
shared_ptr<Behavior> ObjectFlow::transformation() const {
    return transformation_;
}

/// <summary>
/// transformation setter
/// A Behavior used to change or replace object tokens flowing along the ObjectFlow.
/// </summary>
void ObjectFlow::setTransformation(shared_ptr<Behavior> value) {
    transformation_ = value;
}

} // namespace uml
